package com.zzu.base.generator;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class BaseCodeGenerator {
    // 直接设置数据库连接信息（不依赖 Spring 注入）
    private static final String URL = "jdbc:mysql://localhost:3306/base?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC";
    private static final String USERNAME = "yuban233";
    private static final String PASSWORD = "q13525547983";

    public static void main(String[] args) {
        // 使用绝对路径确保文件可创建
        String outputDir = System.getProperty("user.dir") + "/src/main/output";

        FastAutoGenerator.create(URL, USERNAME, PASSWORD)
                .globalConfig(builder -> {
                    builder.author("yuban233")
                            .outputDir(outputDir); // 使用绝对路径
                })
                .packageConfig(builder -> {
                    builder.parent("com.zzu")
                            .moduleName("base")
                            .entity("entity")
                            .mapper("mapper")
                            .controller("controller")
                            .service("service")
                            .serviceImpl("service.impl");
                })
                .strategyConfig(builder -> {
                    builder.addInclude("user", "role", "permission")
                            .entityBuilder()
                            .enableLombok()
                            .enableTableFieldAnnotation()
                            .controllerBuilder()
                            .enableRestStyle();
                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}